package com.sxfq.loansupermarket.backsystem.modular.marketing.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Deptinfos;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Role;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.*;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.core.util.DateUtil;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.core.util.ToolUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.service.IGetListService;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.SearchReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.TongJiInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.service.IReservationsMyWorkService;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.DepartmentInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.IConsultantService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @author py
 * @Date
 */
@Controller
@RequestMapping("/reservationsMyWork")
public class ReservationsMyWorkController extends BaseController {
    @Autowired
    IReservationsMyWorkService reservationsMyWorkService;

    @Autowired
    IGetListService getListService;

    @Autowired
    private SqlMapper sqlMapper;

    @Autowired
    IConsultantService service;

    private String PREFIX = "/marketing/reservations/";

    /**
     * 跳转到市场预约  未到
     */
    @RequestMapping("")
    public String reservationsNoArrived(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getRolelist() == null) {
            String selectsql = "select * from role a where a.pid=(select id from role a where a.name='市场') group by a.num;";
            List<Role> rolelist = sqlMapper.selectList(selectsql, Role.class);
            ShiroKit.getUser().setRolelist(rolelist);
        }
        if (ShiroKit.getUser().getArealist() == null) {
            String sql1 = "select area_abbreviation as areaAbbreviation,area as area from dept a where length(a.pids)>4 " +
                    " and version='" + ShiroKit.getUser().getCompanyVersion() + "' group by a.area order by a.num desc";
            List<Deptinfos> arealist = sqlMapper.selectList(sql1, Deptinfos.class);
            ShiroKit.getUser().setArealist(arealist);
        }
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("arealist", ShiroKit.getUser().getArealist());
        model.addAttribute("rolelist", ShiroKit.getUser().getRolelist());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "reservations_my_work.html";
    }

    /**
     * 市场部预约管理建档
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object reservationsRecord(SearchReservationsInfo info, HttpServletRequest request) {
        Page<ReservationsInfo> page = new PageFactory<ReservationsInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<ReservationsInfo> list = reservationsMyWorkService.selectPageListByStatusMapWD(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = reservationsMyWorkService.selectPageListByStatusMapWD(page, info);
            }
            page.setRecords(list);
            page.setTotal(reservationsMyWorkService.getQueryPagesCountWD(page, info));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 未到点击姓名跳转客户管理详情页面
     */
    @RequestMapping(value = "/to_reservationsNotDetail/{id}")
    public String to_reservationsNotDetail(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(id)) {
            return "/errorClose.html";
        }
        try {
            String sql = "select " +
                    "  (CASE a.customer_sex  " +
                    "  WHEN 1 THEN  " +
                    "  '男'  " +
                    "  WHEN 2 THEN  " +
                    "  '女'  " +
                    "  ELSE  " +
                    "  '未知'  " +
                    "  END  " +
                    " ) as sex ,left(a.appointment_time,19) as appointmentTime,left(a.lasthuifangtime,19) as lasthuifangtime," +
                    "left(a.filing_time,19) as filingTime,a.* from reservations_info a where id= '" + id + "' limit 0,1";
            ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql, ReservationsInfo.class);
            if (ShiroKit.getUser().getRefereeShipInfoList() == null) {
                String getListSql = "select id,referee_ship as refereeShip from referee_ship_info order by num asc;";
                List<RefereeShipInfo> refereeShipList = sqlMapper.selectList(getListSql, RefereeShipInfo.class);
                ShiroKit.getUser().setRefereeShipInfoList(refereeShipList);
            }
            if (ShiroKit.getUser().getEconomicAbilityList() == null) {
                String getListSql = "select id, economic_ability from economic_ability_info order by num asc;";
                List<EconomicAbilityInfo> economicAbilityList = sqlMapper.selectList(getListSql, EconomicAbilityInfo.class);
                ShiroKit.getUser().setEconomicAbilityList(economicAbilityList);
            }
            if (ShiroKit.getUser().getDepartmentList() == null) {
                String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
                List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
                ShiroKit.getUser().setDepartmentList(departmentList);
            }
            if (ShiroKit.getUser().getCharactersList() == null) {
                String getListSql = "select id, characters from character_info order by num asc;";
                List<CharacterInfo> charactersList=sqlMapper.selectList(getListSql,CharacterInfo.class);
                ShiroKit.getUser().setCharactersList(charactersList);
            }
            if (ShiroKit.getUser().getOccupationInfoList() == null) {
                String getListSql = "select id, occupation from occupation_info where isshow=1 order by num asc;";
                List<OccupationInfo> occupationList = sqlMapper.selectList(getListSql, OccupationInfo.class);
                ShiroKit.getUser().setOccupationInfoList(occupationList);
            }
            if (ShiroKit.getUser().getGetMedium() == null) {
                List<Map<String, Object>> getMedium = getListService.getMedium();
                ShiroKit.getUser().setGetMedium(getMedium);
            }
            if (ShiroKit.getUser().getConsumptionHabitsList() == null) {
                String getListSql = "select id, consumption_habits from consumption_habits_info order by  num asc;";
                List<ConsumptionHabitsInfo> consumptionHabitsList = sqlMapper.selectList(getListSql, ConsumptionHabitsInfo.class);
                ShiroKit.getUser().setConsumptionHabitsList(consumptionHabitsList);
            }
            model.addAttribute("consumptionHabitsList", ShiroKit.getUser().getConsumptionHabitsList());
            model.addAttribute("refereeShipList", ShiroKit.getUser().getRefereeShipInfoList());
            model.addAttribute("economicAbilityList", ShiroKit.getUser().getEconomicAbilityList());
            model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
            model.addAttribute("charactersList", ShiroKit.getUser().getCharactersList());
            model.addAttribute("occupationList", ShiroKit.getUser().getOccupationInfoList());
            model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
            model.addAttribute("roleName", ShiroKit.getUser().getRoleName());
            model.addAttribute("reservationsInfo", reservationsInfo);
            model.addAttribute("userName", ShiroKit.getUser().getAccount());
            model.addAttribute("getMedium", ShiroKit.getUser().getGetMedium());
            return PREFIX + "reservationsNotDetail.html";
        } catch (Exception e) {
            return "/errorClose.html";
        }
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/tongji", method = RequestMethod.GET)
    @ResponseBody
    public List<TongJiInfo> change(String param1, String param2, String param3, String param4, String param5, String param6, String param7, String param8,
                                   String param9, String param10, String param11, String param12, String param13, String param14) throws Exception {
        //1.获取当前日期，格式为yyyy-MM-dd hh:mm:ss
        String currentDate = DateUtil.getTime(new Date()).substring(0, 10);//取今天的年月日
        //获取昨天日期字符串 格式为yyyy-MM-dd hh:mm:ss
        String lastDate = DateUtil.getAfterDayDate("-1").substring(0, 10);//取昨日 的年月日
        //获取当月的字符串
        String currerntMonth = currentDate.substring(0, 7);//yyyy-mm
        //获取上月日期
        String lastMonth = DateUtil.getAfterDayMonth("-1").substring(0, 7);//取上月的年月
        String contitionInfo = "";
        if (StringUtils.isNotEmpty(param1) && !"请选择".equals(param1)) {
            String outpatientName = "";
            String outpatientName2[] = param1.split(",");
            if (outpatientName2.length == 1) {
                outpatientName = outpatientName2[0];
            } else {
                for (int i = 0; i < outpatientName2.length; i++) {
                    if (i == (outpatientName2.length - 1)) {
                        outpatientName += "'" + outpatientName2[i];
                    } else if (i == 0) {
                        outpatientName += outpatientName2[i] + "'" + ",";
                    } else {
                        outpatientName += "'" + outpatientName2[i] + "'" + ",";
                    }
                }
            }
            contitionInfo += " and t.outpatient_name in ( '" + outpatientName + "') ";
        }
        if (StringUtils.isNotBlank(param2)) {
            contitionInfo += " and t.follower in (select t1.account from user t1 where  t1.roleid='" + param2 + "') ";
        }
        if (StringUtils.isNotBlank(param3)) {
            contitionInfo += " and t.appointment_pay_service= '" + param3 + "' ";
        }
        if (StringUtils.isNotBlank(param4)) {
            contitionInfo += " and t.archiving= '" + param4 + "' ";
        }
        if (StringUtils.isNotBlank(param5)) {
            contitionInfo += " and t.follower= '" + param5 + "' ";
        }
        if (StringUtils.isNotBlank(param6)) {
            contitionInfo += " and t.access_disease= '" + param6 + "' ";
        }
        if (StringUtils.isNotBlank(param7)) {
            if (!"请选择".equals(param7)) {
                contitionInfo += " and t.one_channel= '" + param7 + "' ";
            }
        }
        if (StringUtils.isNotBlank(param8)) {
            if (!"请选择".equals(param8)) {
                contitionInfo += " and t.two_channel= '" + param8 + "' ";
            }
        }
        if (StringUtils.isNotBlank(param9)) {
            if (!"请选择".equals(param9)) {
                contitionInfo += " and t.thr_channel= '" + param9 + "' ";
            }
        }
        if (StringUtils.isNotEmpty(param10) && !"请选择".equals(param10)) {
            String statuss = "";
            String statuss2[] = param10.split(",");
            if (statuss2.length == 1) {
                statuss = statuss2[0];
            } else {
                for (int i = 0; i < statuss2.length; i++) {
                    if (i == (statuss2.length - 1)) {
                        statuss += "'" + statuss2[i];
                    } else if (i == 0) {
                        statuss += statuss2[i] + "'" + ",";
                    } else {
                        statuss += "'" + statuss2[i] + "'" + ",";
                    }
                }
            }
            contitionInfo += " and t.statuss in ( '" + statuss + "') ";
        }
        if (StringUtil.isNotEmpty(param11) && !"请选择".equals(param11)) {
            String area = "";
            String area2[] = param11.split(",");
            if (area2.length == 1) {
                area = area2[0];
            } else {
                for (int i = 0; i < area2.length; i++) {
                    if (i == (area2.length - 1)) {
                        area += "'" + area2[i];
                    } else if (i == 0) {
                        area += area2[i] + "'" + ",";
                    } else {
                        area += "'" + area2[i] + "'" + ",";
                    }
                }
            }
            contitionInfo += " and t.outpatient_name in (select a.simplename from dept a where a.area_abbreviation in ('" + area + "')) ";
        }
        if (StringUtils.isNotBlank(param13)) {
            contitionInfo += " and t.status= '" + param13 + "' ";
        }
        //姓名   电话   微信  预约号
        if (StringUtils.isNotBlank(param14)) {
            contitionInfo += " and (t.customer_name like CONCAT('%" + param14 + "%') or t.customer_phone like CONCAT('%" + param14 + "%') " +
                    " or t.customer_phone2 like CONCAT('%" + param14 + "%') " +
                    " or t.wechat_number like CONCAT('%" + param14 + "%') or t.reservations_num like CONCAT('%" + param14 + "%') " +
                    " or t.identification_number like CONCAT('%" + param14 + "%') or t.key_word like CONCAT('%" + param14 + "%') " +
                    " or t.szm like CONCAT('%" + param14 + "%')) ";
        }
        contitionInfo += "  group by t.id) t ";
        //查询待回访
        String sql = "select count(*) as countNum from (select id from reservations_infosc t where left(appointment_time,10) = '" + param12 + "' " + contitionInfo +
                //查询已回访
                " union all select count(*) as countNum from (select id from reservations_infosc t where huifang like '%" + param12 + "%' " + contitionInfo;
        List<TongJiInfo> tongJiInfoList = sqlMapper.selectList(sql, TongJiInfo.class);
        return tongJiInfoList;
    }

    //已到导出
    @RequestMapping(value = "/reservationsExportWD")
    public void reservationsExportYD(@RequestParam(required = false) String arrivalStore,
                                     @RequestParam(required = false) String department,
                                     @RequestParam(required = false) String reach,
                                     @RequestParam(required = false) String area,
                                     @RequestParam(required = false) String appointmentPayService,
                                     @RequestParam(required = false) String archiving,
                                     @RequestParam(required = false) String follower,
                                     @RequestParam(required = false) String accessDisease,
                                     @RequestParam(required = false) String oneChannel,
                                     @RequestParam(required = false) String twoChannel,
                                     @RequestParam(required = false) String thrChannel,
                                     @RequestParam(required = false) String statuss,
                                     @RequestParam(required = false) String status,
                                     @RequestParam(required = false) String startTime,
                                     @RequestParam(required = false) String isReturn,
                                     @RequestParam(required = false) String startFilingTime,
                                     @RequestParam(required = false) String endFilingTime,
                                     @RequestParam(required = false) String startAppointmentTime,
                                     @RequestParam(required = false) String endAppointmentTime,
                                     @RequestParam(required = false) String outpatientName,
                                     HttpServletResponse response) {
        try {
            SearchReservationsInfo searchInfo = new SearchReservationsInfo();
            searchInfo.setArrivalStore(arrivalStore);
            searchInfo.setDepartment(department);
            searchInfo.setReach(reach);
            searchInfo.setAppointmentPayService(appointmentPayService);
            searchInfo.setArchiving(archiving);
            searchInfo.setFollower(follower);
            searchInfo.setArea(area);
            searchInfo.setAccessDisease(accessDisease);
            searchInfo.setOneChannel(oneChannel);
            searchInfo.setTwoChannel(twoChannel);
            searchInfo.setThrChannel(thrChannel);
            searchInfo.setStatuss(statuss);
            searchInfo.setStatus(status);
            searchInfo.setStartTime(startTime);
            searchInfo.setIsReturn(isReturn);
            searchInfo.setStartFilingTime(startFilingTime);
            searchInfo.setEndFilingTime(endFilingTime);
            searchInfo.setStartAppointmentTime(startAppointmentTime);
            searchInfo.setEndAppointmentTime(endAppointmentTime);
            searchInfo.setOutpatientName(outpatientName);
            List<ReservationsInfo> list = reservationsMyWorkService.reservationsExportWD(searchInfo);
            // 解析成excel文件
            // 第一步，创建一个webbook，对应一个Excel文件
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步，在wb中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("前端导出");
//            if("1".equals(pageType)){
            for (int i = 0; i < 26; i++) {
                sheet.setColumnWidth(i, 24 * 256);
            }
            // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
            HSSFRow row = sheet.createRow(0);
            // 第四步，创建单元格，并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);// 创建一个居中格式
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("姓名");
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue("性别");
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue("年龄");
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue("电话号码");
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue("疾病类型");
            cell.setCellStyle(style);
            cell = row.createCell(5);
            cell.setCellValue("咨询内容");
            cell.setCellStyle(style);
            cell = row.createCell(6);
            cell.setCellValue("媒体来源");
            cell.setCellStyle(style);
            cell = row.createCell(7);
            cell.setCellValue("详细来源");
            cell.setCellStyle(style);
            cell = row.createCell(8);
            cell.setCellValue("搜索关键词");
            cell.setCellStyle(style);
            cell = row.createCell(9);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            cell = row.createCell(10);
            cell.setCellValue("客服");
            cell.setCellStyle(style);
            cell = row.createCell(11);
            cell.setCellValue("到店时间");
            cell.setCellStyle(style);
            cell = row.createCell(12);
            cell.setCellValue("添加时间");
            cell.setCellStyle(style);
            cell = row.createCell(13);
            cell.setCellValue("接待医生");
            cell.setCellStyle(style);
            cell = row.createCell(14);
            cell.setCellValue("消费状态");
            cell.setCellStyle(style);
            cell = row.createCell(15);
            cell.setCellValue("消费项目");
            cell.setCellStyle(style);
            cell = row.createCell(16);
            cell.setCellValue("消费明细");
            cell.setCellStyle(style);
            cell = row.createCell(17);
            cell.setCellValue("回访时间");
            cell.setCellStyle(style);
            cell = row.createCell(18);
            cell.setCellValue("回访记录");
            cell.setCellStyle(style);
            cell = row.createCell(19);
            cell.setCellValue("医生点评");
            cell.setCellStyle(style);
            cell = row.createCell(20);
            cell.setCellValue("部门");
            cell.setCellStyle(style);
            cell = row.createCell(21);
            cell.setCellValue("到院状态");
            cell.setCellStyle(style);
            cell = row.createCell(22);
            cell.setCellValue("微信");
            cell.setCellStyle(style);
            cell = row.createCell(23);
            cell.setCellValue("跟进人");
            cell.setCellStyle(style);
            cell = row.createCell(24);
            cell.setCellValue("预约门诊");
            cell.setCellStyle(style);
            cell = row.createCell(25);
            cell.setCellValue("初诊时间");
            cell.setCellStyle(style);
            cell = row.createCell(26);
            cell.setCellValue("一级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(27);
            cell.setCellValue("跟踪状态");
            cell.setCellStyle(style);
            cell = row.createCell(28);
            cell.setCellValue("预约号");
            cell.setCellStyle(style);

            // 填充数据
            for (int i = 0; i < list.size(); i++) {
                ReservationsInfo map = list.get(i);
                row = sheet.createRow(i + 1);
                String reservationsNum = map.getReservationsNum();
                String customerName = map.getCustomerName();
                String customerPhone = map.getCustomerPhone();
                String remarks = map.getRemarks();
                String wechatNumber = map.getWechatNumber();
                status = map.getStatus();
                statuss = map.getStatuss();
                String appointmentTime = map.getAppointmentTime();
                String huifang = map.getHuifang();
                String jiedaiContent = map.getJiedaiContent();
                archiving = map.getArchiving();
                String filingTime = map.getFilingTime();
                String keyWord = map.getKeyWord();
                String firstVisitDate = map.getFirstVisitDate();  //首次到店时间
                oneChannel = map.getOneChannel();
                twoChannel = map.getTwoChannel();
                thrChannel = map.getThrChannel();
                String sex = map.getSex();
                follower = map.getFollower();
                Double money = 0.00;
                if (map.getMoney() != null) {
                    money = map.getMoney();
                }
                String tcName = map.getTcName();
                int customerAge = 0;
                if (map.getCustomerAge() != null) {
                    customerAge = map.getCustomerAge();
                }
                String dealStatus = map.getDealStatus();
                appointmentPayService = map.getAppointmentPayService();
                String accessDiseases = map.getAccessDisease();
                arrivalStore = map.getArrivalStore();
                String expenditureProject = map.getExpenditureProject();
                department = map.getDepartment();
                String id = map.getId();
                // 第四步，创建单元格，并设置值
                for (int j = 0; j <= 28; j++) {
                    row.createCell(j).setCellStyle(style);
                }
                row.getCell(0).setCellValue(customerName);
                row.getCell(1).setCellValue(sex);
                row.getCell(2).setCellValue(customerAge);
                row.getCell(3).setCellValue(customerPhone);
                row.getCell(4).setCellValue(appointmentPayService);
                row.getCell(5).setCellValue(accessDiseases);
                row.getCell(6).setCellValue(twoChannel);
                row.getCell(7).setCellValue(thrChannel);
                row.getCell(8).setCellValue(keyWord);
                row.getCell(9).setCellValue(remarks);
                row.getCell(10).setCellValue(archiving);
                row.getCell(11).setCellValue(firstVisitDate);
                row.getCell(12).setCellValue(filingTime);
                row.getCell(13).setCellValue(tcName);
                row.getCell(14).setCellValue(dealStatus);
                row.getCell(15).setCellValue(expenditureProject);
                row.getCell(16).setCellValue(money);
                row.getCell(17).setCellValue(appointmentTime);
                row.getCell(18).setCellValue(huifang);
                row.getCell(19).setCellValue(jiedaiContent);
                row.getCell(20).setCellValue(department);
                row.getCell(21).setCellValue(status);
                row.getCell(22).setCellValue(wechatNumber);
                row.getCell(23).setCellValue(follower);
                row.getCell(24).setCellValue(arrivalStore);
                row.getCell(25).setCellValue(firstVisitDate);
                row.getCell(26).setCellValue(oneChannel);
                row.getCell(27).setCellValue(statuss);
                row.getCell(28).setCellValue(reservationsNum);
            }
            String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
            String filename = "data" + date + ".xls";
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
            response.setContentType("application/octet-stream;charset=UTF-8");
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}